package com.foreknow.elm.dao.impl;

import com.foreknow.elm.dao.OrderdetailetDao;
import com.foreknow.elm.po.Orderdetailet;
import com.foreknow.elm.util.DBUtil;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.List;

public class OrderdetailetDaoImpl implements OrderdetailetDao {
    private Connection con;
    private PreparedStatement pst;
    private ResultSet rs;
    @Override
    public int saveOrderDetailet(List<Orderdetailet> list) throws Exception {
        String sql = "INSERT INTO orderdetailet(orderId,foodId,quantity) VALUES (?,?,?)";
        int isRight = 0;
        Orderdetailet orderdetailet = new Orderdetailet();
        try {
            //进行数据库连接
            con = DBUtil.getConnection();
            //传输数据库语句
            pst = con.prepareStatement(sql);
            for (int i = 0; i < list.size(); i++) {
                pst.setInt(1,list.get(i).getOrderId());
                pst.setInt(2,list.get(i).getFoodId());
                pst.setInt(3,list.get(i).getQuantity());
                isRight = pst.executeUpdate();
            }
        }finally {
            DBUtil.close(rs,pst);
        }
        return isRight;
    }
}
